package best.driver.android.TestCase;


import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import best.driver.android.Activity.Base.BaseActivity;
import best.driver.android.AppInfo;
import best.driver.android.BestApp;
import best.driver.android.Map.Address;
import best.driver.android.Map.location.LocationManager;
import best.driver.android.R;
import best.driver.android.RequestFactory;
import best.driver.android.View.BestMapView;
import best.driver.android.common.app.AppProxyFactory;
import best.driver.android.common.network.ApiRequest;
import best.driver.android.common.network.ApiStringRequest;
import best.driver.android.common.network.BestError;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import com.baidu.mapapi.model.LatLng;
import de.greenrobot.event.EventBus;

public class LocationActivity extends BaseActivity{

    long mExitTime;

    @InjectView(R.id.latitude)
    TextView mTvLat;

    @InjectView(R.id.longitude)
    TextView mTvLng;

    @InjectView(R.id.best_map_view)
    BestMapView mMapView;

    @OnClick(R.id.btn_get_location)
    protected void getLocation() {
        LocationManager.getInstance().requestLoc(5000);
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_location_test);
        ButterKnife.inject(this, view);
        EventBus.getDefault().register(this);
        setTopTopic("工作状态");
    }

    public void onEventMainThread(LatLng latLng) {
        mTvLat.setText("Lat: " + latLng.latitude);
        mTvLng.setText("Lng: " + latLng.longitude);
        mMapView.setCenter(latLng);
    }


    @Override
    public void onBackPressed() {
        if ((System.currentTimeMillis() - mExitTime) > 2000) {
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            mExitTime = System.currentTimeMillis();
        } else {
            BestApp.getInstance().exit();
            super.onBackPressed();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


}
